#!/bin/sh

instrumentor_module_name=@instrumentor_module_name@
instrumentor_module="${instrumentor_module_name}.ko"
test_module_name=@test_module_name@
test_module="test_module/${test_module_name}.ko"

test_value_file="/sys/module/${instrumentor_module_name}/parameters/test_value"

if ! @INSMOD@ "${instrumentor_module}" "target_name=${test_module_name}"; then
    printf "Failed to insert instrumentor module into kernel.\n"
    exit 1
fi

if ! @INSMOD@ "${test_module}"; then
    printf "Failed to insert test module into kernel.\n"
    @RMMOD@ "${instrumentor_module_name}"
    exit 1
fi

if ! @RMMOD@ "${test_module}"; then
    printf "Failed to unload test module.\n"
    exit 1
fi

test_value=`cat "${test_value_file}"`

if ! @RMMOD@ "${instrumentor_module}"; then
    printf "Failed to unload instrumentor module.\n"
    exit 1
fi

if test "${test_value}" != "5"; then
    printf "Expected that test value will be 5, but it is ${test_value}.\n"
    exit 1
fi